package jiwei.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
    @Autowired
    RefererProp refererProp;

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //referer拦截
        if (refererProp.getEnabled()) {
            registry.addInterceptor(new RefererInterceptor(refererProp))
                    .addPathPatterns("/**") //所有请求都被拦截包括静态资源
                    .excludePathPatterns("/", "/login",
                            "/css/**", "/fonts/**", "/images/**", "/js/**"); //放行的请求
            //.addPathPatterns("/**").excludePathPatterns("/", "/login", "/logout");
        }
    }
}
